import collections

class Solution:
    def groupAnagrams(self, strs):
        res = dict()
        for s in strs:
            s_sorted = ''.join(sorted(s))
            if s_sorted not in res:
                res[s_sorted] = [s]
            else:
                res[s_sorted].append(s)
        return list(res.values())


strs = ["eat", "tea", "tan", "ate", "nat", "bat"]
tester = Solution()
print(tester.groupAnagrams(strs))


